import { _decorator, Component, EventTouch, Node, UITransform, Vec3 } from 'cc';
const { ccclass, property } = _decorator;

@ccclass('TalentPanel')
export class TalentPanel extends Component {


    @property(Node) ndTalents: Node;



    protected onEnable(): void {
        this.node.on(Node.EventType.TOUCH_START, this.onTouchStart, this, true);
        this.node.on(Node.EventType.TOUCH_END, this.onTouchEnd, this, true);
        this.node.on(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this, true);
    }

    protected onDisable(): void {
        
        this.node.off(Node.EventType.TOUCH_START, this.onTouchStart, this, true);
        this.node.off(Node.EventType.TOUCH_END, this.onTouchEnd, this, true);
        this.node.off(Node.EventType.TOUCH_CANCEL, this.onTouchCancel, this, true);
    }


    start() {

    }

    update(deltaTime: number) {
        
    }

    onTouchStart(event: EventTouch){
        const v2 = event.getUIStartLocation();
        console.log('什么位置', v2);
        // 相对位置
        const pos = this.node.getComponent(UITransform).convertToNodeSpaceAR(new Vec3().set(v2.x, v2.y, 0));
        console.log('相对位置', pos);

        console.log('pos', pos.x, pos.y);
        if(pos.x < -200 || pos.x > 200 ) {
            this.node.active = false;
        }
    }

    onTouchEnd(){
        
    }

    onTouchCancel(){
        
    }
}


